package light.mvc.model.admin;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import light.mvc.model.base.IdEntity;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table(name = "role")
@DynamicInsert(true)
@DynamicUpdate(true)
public class Trole extends IdEntity implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	
	private String name;
	private String description;
	
	private Set<Tresource> resources = new HashSet<Tresource>(0);
	private Set<Tuser> users = new HashSet<Tuser>(0);
	
	@OneToMany(mappedBy = "role")
	public Set<Tuser> getUsers() {
		return users;
	}
	public void setUsers(Set<Tuser> users) {
		this.users = users;
	}
	
	@ManyToMany()
	@JoinTable(name = "role_resource", 
	joinColumns={@JoinColumn(name="role_id",nullable=false,updatable=false)},
	inverseJoinColumns={@JoinColumn(name="resource_id",nullable=false,updatable=false)}
	)
	public Set<Tresource> getResources() {
		return resources;
	}
	public void setResources(Set<Tresource> resources) {
		this.resources = resources;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
}